package com.kafka.learn.kafka.first;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.stereotype.Component;

import java.util.Properties;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


/**
 * @className KafkaProducerDemo
 * @description 暂时的kafka生产者 待删除
 * @author 郭辉
 * @date 2021/12/23 20:28
 * @company 海康威视
 * @since 1.0
 */
@Component
public class KafkaProducerDemo1 {

    private static final String BROKER_LIST = "localhost:9092";

    private static final String TOPIC = "SNAP_IMAGE_INFO_TOPIC";

    public static void main(String[] args) {
        String str1 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.553909,\n" +
                "\t\t    \"latitude\": 39.862099,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

        String str2 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2" +
                "Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang." +
                "com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.555347,\n" +
                "\t\t    \"latitude\": 39.863409,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "            \"identify\": [{\n" +
                "            \t\"candidate\": [{\n" +
                "            \t\t\"similarity\": 1, \n" +
                "                    \"nowCreate\": true, \n" +
                "                    \"blacklist_id\": \"1811121450265681\",\n" +
                "                    \"human_id\": \"0944_8aMaSXCSS8oeS8N6Me6CQqECCQG_GXIeaq1I\",\n" +
                "                    \"human_data\": [{\n" +
                "                    \t\"face_picurl\": \"https://img0.baidu.com/it/u=3460173805,2891655665&" +
                "fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500\",\n" +
                "                        \"face_id\": 1\n" +
                "                   }],\n" +
                "\t\t\t\t\t\"reserve_field\":\"{\\\"humanCrednum\\\":\\\"\\\",\\\"humanName\\\":\\\"\\\",\\\"" +
                "humanMale\\\":0,\\\"humanCredtype\\\":111,\\\"birthDate\\\":\\\"\\\",\\\"humanCity\\\":\\\"\\\"}\",\n" +
                "\t\t\t\t\t\"blacklist_ids\": \"1576149277115\" \n" +
                "               }]\n" +
                "            }],\n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

        String str3 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.553909,\n" +
                "\t\t    \"latitude\": 39.862099,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

        String str4 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2" +
                "Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang." +
                "com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.55466,\n" +
                "\t\t    \"latitude\": 39.864693,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "            \"identify\": [{\n" +
                "            \t\"candidate\": [{\n" +
                "            \t\t\"similarity\": 1, \n" +
                "                    \"nowCreate\": true, \n" +
                "                    \"blacklist_id\": \"1811121450265681\",\n" +
                "                    \"human_id\": \"0944_8aMaSXCSS8oeS8N6Me6CQqECCQG_GXIeaq1I\",\n" +
                "                    \"human_data\": [{\n" +
                "                    \t\"face_picurl\": \"https://img0.baidu.com/it/u=3460173805,2891655665&" +
                "fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500\",\n" +
                "                        \"face_id\": 1\n" +
                "                   }],\n" +
                "\t\t\t\t\t\"reserve_field\":\"{\\\"humanCrednum\\\":\\\"\\\",\\\"humanName\\\":\\\"\\\",\\\"" +
                "humanMale\\\":0,\\\"humanCredtype\\\":111,\\\"birthDate\\\":\\\"\\\",\\\"humanCity\\\":\\\"\\\"}\",\n" +
                "\t\t\t\t\t\"blacklist_ids\": \"1576149277115\" \n" +
                "               }]\n" +
                "            }],\n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

                String str5 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2" +
                "Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang." +
                "com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.555347,\n" +
                "\t\t    \"latitude\": 39.863409,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "            \"identify\": [{\n" +
                "            \t\"candidate\": [{\n" +
                "            \t\t\"similarity\": 1, \n" +
                "                    \"nowCreate\": true, \n" +
                "                    \"blacklist_id\": \"1811121450265681\",\n" +
                "                    \"human_id\": \"0944_8aMaSXCSS8oeS8N6Me6CQqECCQG_GXIeaq1I\",\n" +
                "                    \"human_data\": [{\n" +
                "                    \t\"face_picurl\": \"https://img0.baidu.com/it/u=3460173805,2891655665&" +
                "fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500\",\n" +
                "                        \"face_id\": 1\n" +
                "                   }],\n" +
                "\t\t\t\t\t\"reserve_field\":\"{\\\"humanCrednum\\\":\\\"\\\",\\\"humanName\\\":\\\"\\\",\\\"" +
                "humanMale\\\":0,\\\"humanCredtype\\\":111,\\\"birthDate\\\":\\\"\\\",\\\"humanCity\\\":\\\"\\\"}\",\n" +
                "\t\t\t\t\t\"blacklist_ids\": \"1576149277115\" \n" +
                "               }]\n" +
                "            }],\n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";
            String str6 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2" +
                "Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang." +
                "com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.553319,\n" +
                "\t\t    \"latitude\": 39.863293,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "            \"identify\": [{\n" +
                "            \t\"candidate\": [{\n" +
                "            \t\t\"similarity\": 1, \n" +
                "                    \"nowCreate\": true, \n" +
                "                    \"blacklist_id\": \"1811121450265681\",\n" +
                "                    \"human_id\": \"0944_8aMaSXCSS8oeS8N6Me6CQqECCQG_GXIeaq1I\",\n" +
                "                    \"human_data\": [{\n" +
                "                    \t\"face_picurl\": \"https://img0.baidu.com/it/u=3460173805,2891655665&" +
                "fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500\",\n" +
                "                        \"face_id\": 1\n" +
                "                   }],\n" +
                "\t\t\t\t\t\"reserve_field\":\"{\\\"humanCrednum\\\":\\\"\\\",\\\"humanName\\\":\\\"\\\",\\\"" +
                "humanMale\\\":0,\\\"humanCredtype\\\":111,\\\"birthDate\\\":\\\"\\\",\\\"humanCity\\\":\\\"\\\"}\",\n" +
                "\t\t\t\t\t\"blacklist_ids\": \"1576149277115\" \n" +
                "               }]\n" +
                "            }],\n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

        String str7 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.555347,\n" +
                "\t\t    \"latitude\": 39.863409,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";
        String str8 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.55466,\n" +
                "\t\t    \"latitude\": 39.864693,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";
        String str9 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.553738,\n" +
                "\t\t    \"latitude\": 39.866958,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";
        String str10 = "{\n" +
                "    \n" +
                "    \"dateTime\": \"2009-11-14T15:27Z\",\n" +
                "    \"captureLibResult\": [{\n" +
                "        \"image\": \"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%" +
                "2Fuploads%2Fitem%2F201607%2F04%2F20160704115913_Ei3fG.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=" +
                "2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643351458&t=9bb8f2ca50ad68383c820fb1b02af1a6\","+
                "        \"targetAttrs\": { \n" +
                "            \"deviceId\": \"1\",\n" +
                "\t\t\t\"cameraIndexCode\": \"3301023820382193\", \n" +
                "            \"deviceChannel\": 1,\n" +
                "            \"deviceType\": 1,\n" +
                "            \"deviceName\": \"shebei\",\n" +
                "\t\t    \"longitude\": 116.558019,\n" +
                "\t\t    \"latitude\": 39.862313,\n" +
                "\t\t    \"name\": \"张三\",\n" +
                "\t\t    \"registerGender\": \"male\",\n" +
                "\t\t    \"bornTime\": \"2016-01-30\",\n" +
                "\t\t    \"address\": \"中国浙江省\",\n" +
                "\t\t    \"certificateNumber\": \"111111111111111111\",\n" +
                "\t\t    \"alarmState\": true,\n" +
                "            \"faceTime\": \"2009-11-14T15:27:00.000Z\",\n" +
                "        },\n" +
                "        \"faces\": [{      \n" +
                "    \t}] \n" +
                "\t}], \n" +
                "}";

        for (int i = 0; i < 10; i++) {
            switch (i){
                case 1:
                    new Thread(()->{
                        pushMessage(str1);
                    }).start();
                    break;
                case 2:
                    new Thread(()->{
                        pushMessage(str2);
                    }).start();
                    break;
                case 3:
                    new Thread(()->{
                        pushMessage(str3);
                    }).start();
                    break;
                case 4:
                    new Thread(()->{
                        pushMessage(str4);
                    }).start();
                    break;
                case 5:
                    new Thread(()->{
                        pushMessage(str5);
                    }).start();
                    break;
                case 6:
                    new Thread(()->{
                        pushMessage(str6);
                    }).start();
                    break;
                case 7:
                    new Thread(()->{
                        pushMessage(str7);
                    }).start();
                    break;
                case 8:
                    new Thread(()->{
                        pushMessage(str8);
                    }).start();
                    break;
                case 9:
                    new Thread(()->{
                        pushMessage(str9);
                    }).start();
                    break;
                case 10:
                    new Thread(()->{
                        pushMessage(str10);
                    }).start();
                    break;
                default:
                    new Thread(()->{
                        pushMessage(str1);
                    }).start();
                    break;
            }

        }
    }

    public static void pushMessage(String str){
        Properties properties = new Properties();
        /**
         * 设置key序列化器
         * */
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        /**
         * 设置一个重试次数
         * */
        properties.put(ProducerConfig.RETRIES_CONFIG,10);
        /**
         * 设置值序列化器
         * */
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
        /**
         * 设置集群地址
         * */
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,BROKER_LIST);
        /**
         * 加一个拦截器 (可以为自定义，也可以使用Kafka定义好的)
         * */
//        properties.put(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG,ProduceInceptor.class.getName());
        /**
         * 消息发送者实例化
         * */
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
        /**
         * 封装了发送的消息对象（包括消息的topic，消息内容等）
         * */
        /*ProducerRecord<String, String> record = new ProducerRecord<>(topic,"kafka-demo",
                "{\n" +
                        "\t\"ipAddress \": \"13132\",\n" +
                        "\t\"dateTime\": \"2009-11-14T15:27Z\",\n" +
                        "\t\"componentId \": \"xxx \",\n" +
                        "\t\"captureLibResult\": [{\n" +
                        "\t\t\"image \": \"http: //10.7.52.174:8080/kms/services/rest/dataInfoSer7ffffffffc1a0316369671314\",\n" +
                        "\t\t\"targetAttrs\": {\n" +
                        "\t\t\t\"name\": \"张三\"\n" +
                        "\t\t}\n" +
                        "\t}]\n" +
                        "}");*/

        String demmo = "kafka-demo";
        Random random = new Random();
        int i = random.nextInt();
        ProducerRecord<String, String> record = null;
//            record = new ProducerRecord<>(TOPIC,"kafka-demo",str1);
        record = new ProducerRecord<>(TOPIC,demmo,str);


        try {
            /**
             * 同步发送操作
             * */
            Future<RecordMetadata> send = producer.send(record);
            /**
             * RecordMetadata 封装了当前发送的消息的topic，分区，偏移量等
             * */
            RecordMetadata recordMetadata = send.get();
            //获取topic
            recordMetadata.topic();
            //分区
            recordMetadata.partition();
            //偏移量
            recordMetadata.offset();

        } catch (InterruptedException e) {
//            LOGGER.error(e.getMessage());
        } catch (ExecutionException e) {
//            LOGGER.error(e.getMessage());
        }
        producer.close();
    }
}
